//
//  JYNavigationBarRightView.m
//  client
//
//  Created by Evan on 2018/3/18.
//

#import "JYNavigationBarRightView.h"
#import "Masonry.h"

@implementation JYNavigationBarRightView

- (instancetype)init {
    
    if (self = [super init]) {
        
        self.frame = CGRectMake(0, 0, 76, 30);
        
        // logo
        self.iconImageView = [[UIImageView alloc] init];
        self.iconImageView.image = [UIImage imageNamed:@"logo"];
        
        self.saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.saveButton setHidden:YES];
        [self.saveButton setTitle:@"保存" forState:UIControlStateNormal];
        [self.saveButton setTitle:@"保存" forState:UIControlStateSelected];
        [self.saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
        [self.saveButton.titleLabel setFont:[UIFont systemFontOfSize:14.0f]];
        [self.saveButton addTarget:self action:@selector(save:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(save:)]];
        
        [self addSubview:self.iconImageView];
        [self addSubview:self.saveButton];
        
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(76, 18));
        }];
        [self.saveButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.right.mas_equalTo(self);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
    }
    
    return self;
}

- (void)save:(id)buttonOrGestureRecognizer {
    
    if (self.handler) {
        
        self.handler();
    }
}

- (CGSize)intrinsicContentSize {
    
    return CGSizeMake(76, 30);
}

@end
